import request from "@/utils/request";
import { FlowNodeTaskVo } from "./flowNodeTask.api";

const FLOW_BASE_URL = "/system/flowNode";

const FlowNodeAPI = {
  /**
   * 根据流程id 获取流程节点列表
   * @param queryParams 查询参数
   */
  getNodes(flowId: string) {
    return request<any, FlowNodeVo[]>({
      url: `${FLOW_BASE_URL}/loadByFlowId`,
      method: "get",
      params: { flowId },
    });
  },
};

export default FlowNodeAPI;

/** 流程节点对象 */
export interface FlowNodeVo {
  /** ID */
  id?: string;
  /** 流程节点模板id */
  flowId?: string;
  /** 名称 */
  name: string;
  /** 描述 */
  remark?: string;
  /** 审核方式 */
  auditorType: string | null;
  /** 节点类型 */
  nodeType: string;
  /** 审核不过，回退到哪一个节点sort */
  backNodeId?: number;
  /** 是否替换新的审核节点(排序时)，前端用 */
  isNewBackId?: boolean;
  /** 任务顺序 */
  sort: number;
  /** 任务 */
  flowNodeTasks?: FlowNodeTaskVo[];
}

//************ 枚举 ********** */
// 节点类型
export enum FlowNodeType {
  BUSINESS_NODE = "BUSINESS_NODE",
  AUDITOR_NODE = "AUDITOR_NODE",
}
export const FLOW_NODE_TYPE_LABEL: IConstant = {
  [FlowNodeType.BUSINESS_NODE]: "业务",
  [FlowNodeType.AUDITOR_NODE]: "审核",
};

// 审核类型
export enum FlowAuditorType {
  NO_NEED = "NO_NEED",
  ONE_PASS = "ONE_PASS",
  ALL_PASS = "ALL_PASS",
  MANY_LEVEL = "MANY_LEVEL",
}
export const FLOW_AUDIT_TYPE_LABEL: IConstant = {
  [FlowAuditorType.NO_NEED]: "无需审核",
  [FlowAuditorType.ONE_PASS]: "任意一个通过",
  [FlowAuditorType.ALL_PASS]: "全员通过",
  [FlowAuditorType.MANY_LEVEL]: "多级顺序审核",
};
